// config

var app =
  angular.module('app')
  .config(
    ['$controllerProvider', '$compileProvider', '$filterProvider', '$provide', '$httpProvider', 'ngDialogProvider',
      function ($controllerProvider, $compileProvider, $filterProvider, $provide, $httpProvider, ngDialogProvider) {

        // lazy controller, directive and service
        app.controller = $controllerProvider.register;
        app.directive = $compileProvider.directive;
        app.filter = $filterProvider.register;
        app.factory = $provide.factory;
        app.service = $provide.service;
        app.constant = $provide.constant;
        app.value = $provide.value;

        // 设置默认 fromdata 请求                
        $httpProvider.defaults.transformRequest = function (obj) {
          var arrStr = [];
          for (var p in obj) {
            arrStr.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
          }
          // 设置默认值
          return arrStr.join("&");
        };
        $httpProvider.defaults.headers.post = {
          'Content-Type': 'application/x-www-form-urlencoded'
        }


        ngDialogProvider.setDefaults({
          className: 'ngdialog-theme-default',
          plain: false,
          showClose: true,
          closeByDocument: true,
          closeByEscape: true,
          appendTo: false,
          preCloseCallback: function () {
            console.log('default pre-close callback');
          }
        });


      }
    ]);